home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / backup / kbackup-.000 / KBackup-1.2.7.tar / KBackup / src / restore_src < prev    next >
Text File  |  1996-03-25  |  10KB  |  421 lines

  1. #
  2. # /home/kbackup/.CVSROOT/KBackup/src/restore_src,v 1.17 1996/03/25 14:52:44 kbackup Exp
  3. #
  4. # This file is Copyright (C) 1995 by Karsten Ballⁿder
  5. #                Karsten.Ballueder@stud.uni-karlsruhe.de
  6. #
  7. # It is part of the KBackup package, see the file COPYING for details.
  8. #
  9. #
  10. # subroutines doing all restore operation,
  11. # get loaded by Restore() on demand
  12. #
  13.  
  14. Restore_src_loaded=YES
  15.  
  16. if [ "$ReadData_src_loaded" != "YES" ]
  17. then
  18.     . $SRCDIR/$READDATA_SRC
  19. fi
  20.  
  21. if [ "$Blockdev_src_loaded" != "YES" ]
  22. then
  23.     . $SRCDIR/$BLOCKDEV_SRC
  24. fi
  25.  
  26. Restore_II()
  27. {
  28.     save_options
  29.  
  30.     if [ "$restore_write_log" = "YES" ]
  31.     then
  32.         rest_logfile="$TMP/$TARLOGFILE"
  33.     else
  34.         rest_logfile=/dev/null
  35.     fi
  36.     
  37.     if [ "$scheduled" != "YES" ]
  38.     then
  39.         insert_media
  40.         if [ $? != 0 ]
  41.         then
  42.             return
  43.         fi
  44.     fi
  45.  
  46.     auto_rewind
  47.  
  48.     if [ "$device_type" = "BLOCKDEV" ]
  49.     then
  50.         dirfile="$MOUNTPOINT/$BLOCKDEV_DIRECTORY"
  51.         header="$MOUNTPOINT/$BLOCKDEV_HEADER"
  52.         archive="$MOUNTPOINT/$BLOCKDEV_ARCHIVE"
  53.         get_blockdev READ
  54.     else
  55.         dirfile="$device"
  56.         header="$device"
  57.         archive="$device"
  58.     fi
  59.     
  60.     if [ "$scheduled" = "YES" ]
  61.     then
  62.         echo "Starting scheduled restore at `date`:" >$TMP/$MSGFILE
  63.     else
  64.         Restore_part_I
  65.         if [ $? != 0 ]
  66.         then
  67.             restore_options
  68.             return
  69.         fi
  70.     fi
  71.  
  72.     InfoBox "Filtering list..."
  73.  
  74.     #     - remove all afio specific information from logfile:
  75.     #     - remove one possible remark from tar:
  76.     #     - remove leading slashes:
  77.     #
  78.     #    extract filename from:
  79.     #    ^file size uid gid wday month day hh:mm:ss year perm$
  80.     #    this should handle filenames with ANY characters properly
  81.     $SED "\
  82. 1,$    s/ -- okay$//g
  83. 1,$    s/\.z -- ([0-9][0-9]*\%)$//g
  84. 1,$    s/^tar: .* is the archive; not dumped$//g
  85. 1,1    s/^Generating logfile...$//g
  86. $-3,$    s/^Archive size: .*$//g
  87. $-3,$    s/^[0-9+]* records in$//g
  88. $-3,$    s/^[0-9+]* records out$//g
  89. 1,$    s/^\/\(.*\)$/\1/g
  90. 1,$    s/^\\(.*\) [0-9][0-9]* [^ ][^ ]* [^ ][^ ]* [^ ][^ ]* [^ ][^ ]* [^ ][^ ]* ..:..:.. [^ ][^ ]* [^ ][^ ]*$/\1/g
  91. 1,$    s/^\.\///g
  92. " <$TMP/$DIRLISTFILE >$TMP/$TARLISTFILE
  93.     check_error
  94.  
  95.     InfoBox "Restoring files..."
  96.  
  97.     if [ $compression = PGP ]
  98.     then
  99.         GetPGPPASS
  100.     fi
  101.  
  102.     cd "$restore_dir"
  103.     if [ "$backup_archive_format" = "TAR" ]
  104.     then
  105.         Tar_Restore
  106.  
  107.     else        # AFIO
  108.         Afio_Restore
  109.     fi
  110.     clear_PGP
  111.     if [ "$restore_write_log" = "YES" ]
  112.     then
  113.         logfile="$TMP/RESTORED-`date +'%y-%m-%d--%X'`"
  114.         if [ $scheduled = NO ]
  115.         then
  116.             cat $rest_logfile | $compress >$logfile
  117.             beep
  118.             $DIALOG   --title $logfile --textbox $rest_logfile 23 75
  119.         else
  120.             cat $TMP/$MSGFILE $rest_logfile | $compress >$logfile
  121.             rm -rf $datadir/$schedulename
  122.             rm -f $TMP/$MSGFILE
  123.         fi
  124.     fi
  125.     restore_options
  126.     release_blockdev
  127. }
  128.  
  129. Restore_part_I()
  130. {
  131.     old_compression="$compression"
  132.     
  133.     if [ "$device_type" != "FLOPPY" ]
  134.     then
  135.         if [ -f $device ] ; then # do extra directory file
  136.             dirfile="$device.dir"
  137.         else
  138.             InfoBox "Reading header..."
  139.             read_data -raw $header >$TMP/$TMPFILE 2>$STDERR
  140.             check_error -dev
  141.             if [ $? != 0 ]
  142.             then
  143.                 return 1
  144.             else
  145.                 if read firstline < $TMP/$TMPFILE && test "$firstline" = "#KBackup" 
  146.                 then
  147.                     backup_use_multibuf="???"
  148.                     . $TMP/$TMPFILE
  149.                     compression="$backup_compression"
  150.                     if [ "$backup_use_multibuf" = "YES" ]
  151.                     then
  152.                         use_multibuf="$backup_use_multibuf"
  153.                         multibuf_blksize="$backup_multibuf_blksize"
  154.                         multibuf_nblocks="$backup_multibuf_nblocks"
  155.                         multibuf_seq_info="$backup_multibuf_seq_info"
  156.                     else
  157.                         use_multibuf=NO
  158.                     fi
  159.  
  160.                     $DIALOG   --title "Archive header information" --msgbox "\n\
  161. Archive created by KBackup Version: $backup_version\n\
  162.   files per archive: .............. $backup_filesperarchive\n\
  163. Creation date: .................... $backup_date\n\
  164. Backup type: ...................... $backup_type\n\
  165. Archive format: ................... $backup_archive_format\n\
  166. Compression method: ............... $backup_compression\n\
  167. Directories-only flag: ............ $backup_donly\n\
  168. using Multibuf: ................... $backup_use_multibuf\n\
  169.   blocksize: ...................... $backup_multibuf_blksize\n\
  170.   number of blocks: ............... $backup_multibuf_nblocks\n\
  171.   using sequence information: ..... $backup_multibuf_seq_info\n\
  172. Parent directory of backup: ....... $backup_parent\n" 19 75
  173.                 else
  174.                     ErrorBox "Cannot find a KBackup archive header!"
  175.                     return 1
  176.                 fi
  177.             fi
  178.         fi
  179.     fi
  180.  
  181.     MsgBox \
  182. "You are now prompted to choose
  183. the relative root directory."
  184.  
  185.         if [ "$backup_parent" = "" ]
  186.     then
  187.         backup_parent=/
  188.     fi
  189.     
  190.     choose_dir "$backup_parent"
  191.     restore_dir="$choose_dir_result"
  192.  
  193.     set_compress
  194.  
  195.     restore_all=NO
  196.     while :
  197.     do
  198.     $DIALOG   --menu "Please choose:" 11 75 4\
  199.         A    "Restore all files from archive" \
  200.         C    "Initialise editable list of files from contents directory"\
  201.         L    "Initialise editable list of files from logfile"\
  202.         "<"    "Return to main menu" 2>$TMP/$DIALOGFILE 
  203.     if [ $? = 0 ]
  204.     then
  205.         case `cat $TMP/$DIALOGFILE` in
  206.         A)    InfoBox "Reading directory..." 
  207.             if [ "$device_type" != "FLOPPY" ]
  208.             then
  209.                 read_data $dirfile >$TMP/$TMPFILE  2>$STDERR
  210.                 $uncompress <$TMP/$TMPFILE >$TMP/$DIRLISTFILE 2>$STDERR 3<$TMP/$PHRASEFILE
  211.                 check_compress_success 
  212.                 if [ $? != 0 ]
  213.                 then
  214.                     beep
  215.                 $DIALOG   --title "Error" --msgbox "
  216. Reading/Decompressing contents
  217. directory failed.
  218.  
  219. Error message:
  220. `cat $STDERR`
  221. " 12 40
  222.                     return 1
  223.                 fi
  224.             fi
  225.             restore_all=YES
  226.             return 0
  227.             ;;
  228.         C)    if [ "$device_type" = "FLOPPY" ]
  229.             then
  230.                 ErrorBox "Floppy archives do not have a contents directory!"
  231.                 return 1
  232.             fi
  233.             InfoBox "Reading contents directory..." 
  234.             read_data $dirfile >$TMP/$TMPFILE 2>$STDERR
  235.             check_error 
  236.             if [ $? != 0 ] ; then return 1; fi
  237.             $uncompress <$TMP/$TMPFILE >$TMP/$DIRLISTFILE 2>$STDERR 3<$TMP/$PHRASEFILE
  238.             check_compress_success 
  239.             if [ $? != 0 ]
  240.             then
  241.                 beep
  242.                 $DIALOG   --title "Error" --msgbox "
  243. Reading/Decompressing contents
  244. directory failed.
  245.  
  246. Error message:
  247. `cat $STDERR`
  248. " 12 40
  249.                 return 1
  250.             fi
  251.             check_error
  252.             if [ $? != 0 ] ; then return 1; fi
  253.             clear
  254.             reset
  255.             $EDITOR $TMP/$DIRLISTFILE 2>$STDERR
  256.             check_error
  257.             if [ $? != 0 ] ; then return 1; fi
  258.             $DIALOG --title " Restore " --yesno "Continue with restore?" 7 32 
  259.             if [ $? = 0 ]
  260.             then
  261.                 return 0
  262.             else
  263.                 return 1
  264.             fi
  265.             ;;
  266.         L)    find $datadir/$configname -name "*Log*" -printf "%f %Tx\n" | sort >$TMP/$TMPFILE
  267.             lines=`wc -l <$TMP/$TMPFILE`
  268.             if [ "$lines" = "" -o "$lines" = "0" ]
  269.             then
  270.                 MsgBox "Could not find any logfiles."
  271.                 return 1    # error
  272.             fi
  273.             if [ "$lines" -gt 15 ] ; then lines=15 ; fi
  274.             $DIALOG   --menu "Choose a logfile:" 22 60 $lines \
  275.                 `cat $TMP/$TMPFILE` 2>$TMP/$DIALOGFILE
  276.             check_error
  277.             
  278.             ( uncompress_logfile $datadir/$configname/`cat $TMP/$DIALOGFILE` && cat $TMP/$TMPFILE >$TMP/$DIRLISTFILE ) 2>$STDERR 3<$TMP/$PHRASEFILE
  279.             check_error
  280.             if [ $? != 0 ] ; then return 1; fi
  281.             clear
  282.             reset
  283.             $EDITOR $TMP/$DIRLISTFILE 2>$STDERR
  284.             check_error 
  285.             if [ $? != 0 ] ; then return 1; fi
  286.             $DIALOG --title " Restore " --yesno "Continue with restore?" 7 32 
  287.             if [ $? != 0 ]
  288.             then
  289.                 return 1
  290.             fi
  291.             if [ "$device_type" != "FLOPPY" ]
  292.             then
  293.                 InfoBox "Skipping contents directory..." 
  294.                 read_data $dirfile >/dev/null 2>$STDERR
  295.                 check_error
  296.             fi
  297.             return 0
  298.             ;;
  299.         "<")    compression="$old_compression"
  300.             return 1
  301.             ;;
  302.         esac
  303.     else
  304.         compression="$old_compression"
  305.         return 1
  306.     fi
  307.     done
  308.     return 0
  309. }
  310.  
  311. Tar_Restore()
  312. {
  313.     xopt="$STD_TAROPT_REST"
  314.     
  315.     if [ $restore_all = NO ]
  316.     then
  317.         xopt="$xopt --files-from $TMP/$TARLISTFILE"
  318.     else
  319.         files=
  320.     fi
  321.  
  322.     if [ $followtarops = YES ]
  323.     then
  324.         clear
  325.         reset
  326.         xopt="$xopt -v -v"
  327.         echo "( read_data $archive \
  328.         | $TAR $tar_user_opts $xopt --extract $tarcompress -f - )" >$TMP/$TMPFILE
  329.         . $TMP/$TMPFILE 2>&1 3<$TMP/$PHRASEFILE | tee $rest_logfile
  330.         echo -e "\nPress ENTER to continue..."
  331.         read
  332.     else
  333.         echo "( read_data $archive | $TAR $tar_user_opts $xopt --extract \
  334.         $tarcompress -f - )" >$TMP/$TMPFILE
  335.         . $TMP/$TMPFILE 2>&1 3<$TMP/$PHRASEFILE >$rest_logfile
  336.     fi
  337. }    
  338.  
  339. Afio_Restore()
  340. {
  341.     xopt="$STD_AFIOOPT_REST"
  342.  
  343.     afio_bug_save_programs
  344.  
  345.     if [ "$device_type" = "FLOPPY" ]
  346.     then
  347.         blocks=`echo $floppy_format|$SED '1,$ s/\(.*\)\/.*/\1k/g' `
  348.         xopt="$xopt -F -s $blocks "
  349.     fi
  350.     
  351.     if [ "$protect_newer" = "YES" ]
  352.     then
  353.         xopt="$xopt -n "
  354.     fi
  355.  
  356.     if [ $compression != NONE ]
  357.     then
  358.         xopt="$xopt -Z"
  359.         if [ "$HasAFIO242" != "YES" ]
  360.         then
  361.             if [ $compression != GZIP ]
  362.             then
  363.                 mkdir $TMP/$BINDIR
  364.                 cp $TMP/$COMPRESSFILE  $TMP/$BINDIR/gzip
  365.                 oldpath="$PATH"
  366.                 export PATH="$TMP/$BINDIR:$PATH"
  367.             fi
  368.         else    # new afio
  369.             xopt="$xopt -P \"$compress_program\""
  370.             if [ -n "$decompress_options" ]
  371.             then
  372.                 for i in $decompress_options
  373.                 do
  374.                     xopt="$xopt -Q \"$i\" "
  375.                 done
  376.                 if [ "$compression" = PGP ]
  377.                 then
  378.                     xopt="$xopt -Q -f "
  379.                 fi
  380.             else
  381.                 xopt="$xopt -Q -d -Q -c "
  382.             fi
  383.         fi
  384.     fi
  385.  
  386.     if [ $restore_all = YES ]
  387.     then
  388.         if [ $followtarops = YES ]
  389.         then
  390.             clear
  391.             reset
  392.             echo "( read_data $archive | $AFIO -i $afio_user_opts $xopt -vz - )" >$TMP/$TMPFILE
  393.             . $TMP/$TMPFILE 2>&1 3<$TMP/$PHRASEFILE | tee $rest_logfile 
  394.             echo -en "\nPress RETURN key to continue..."
  395.             read
  396.         else
  397.             echo "( read_data $archive | $AFIO -i $afio_user_opts $xopt -vz - ) ">$TMP/$TMPFILE
  398.             . $TMP/$TMPFILE 2>&1 3<$TMP/$PHRASEFILE >$rest_logfile 
  399.         fi
  400.     else
  401.         if [ $followtarops = YES ]
  402.         then
  403.             clear
  404.             reset
  405.             echo "( read_data $archive | $AFIO -i $afio_user_opts $xopt -vz -w $TMP/$TARLISTFILE - )" >$TMP/$TMPFILE
  406.             . $TMP/$TMPFILE 2>&1 3<$TMP/$PHRASEFILE | tee $rest_logfile 
  407.             echo -en "\nPress RETURN key to continue..."
  408.             read
  409.         else
  410.             echo "( read_data $archive | $AFIO -i $afio_user_opts $xopt -w $TMP/$TARLISTFILE -vz - )" >$TMP/$TMPFILE
  411.             . $TMP/$TMPFILE 2>&1 3<$TMP/$PHRASEFILE >$rest_logfile 
  412.         fi
  413.     fi
  414.     if [ $compression != GZIP -a $compression != NONE ]
  415.     then
  416.         rm -rf $TMP/$BINDIR
  417.         export PATH="$oldpath"
  418.     fi
  419.     afio_bug_restore_path
  420. }
  421.